




std::string toXML() {
	std::string buf("<item");
	if (allow) {
		buf.append(" action=\"allow\"");
	} else {
		buf.append(" action=\"deny\"");
	}
	buf.append(" order=\"").append(order).append("\"");
	if (getType() != undefined) {
		buf.append(" type=\"").append(getType()).append("\"");
	}
	if (!getValue().empty()) {
		buf.append(" value=\"").append(getValue()).append("\"");
	}
	if (isFilterEverything()) {
		buf.append("/>");
	} else {
		buf.append(">");
		if (filterIQ) {
			buf.append("<iq/>");
		}
		if (filterMessage) {
			buf.append("<message/>");
		}
		if (filterPresence_in) {
			buf.append("<presence-in/>");
		}
		if (filterPresence_out) {
			buf.append("<presence-out/>");
		}
		buf.append("</item>");
	}
	return buf;
}


std::string PrivacyItem::PrivacyRule::SUBSCRIPTION_BOTH = "both";
std::string PrivacyItem::PrivacyRule::SUBSCRIPTION_TO = "to";
std::string PrivacyItem::PrivacyRule::SUBSCRIPTION_FROM = "from";
std::string PrivacyItem::PrivacyRule::SUBSCRIPTION_NONE= "none";


PrivacyRule * PrivacyItem::PrivacyRule::fromString(std::string & value) {
	if (!value.empty()) {
		return NULL;
	}
	PrivacyRule * rule = new PrivacyRule();
	rule->setType(atoi(value.c_str()));
	return rule;
}


void PrivacyItem::PrivacyRule::setValue(std::string & value) {
	if(isSubscription()) {
		setSubscriptionValue(value);
	} else {
		this->value = value;
	}
}


void PrivacyItem::PrivacyRule::setSuscriptionValue(std::string & value) {
	std::string setValue = value;
	std::transform(setValue.begin(), setValue.end(), setValue.begin(), ::tolower);
	if ( setValue == SUBSCRIPTION_BOTH 
			|| setValue == SUBSCRIPTION_TO
			|| setValue == SUBSCRIPTION_FROM
			|| setValue == SUBSCRIPTION_NONE) {
		value = setValue;
		// Do nothing
	} else {
		value = "";
	}
}





